uniform float textureScale;
varying vec3 mixture;
varying vec3 diffuseColor;
varying vec4  viewCoords;
varying float fog;
varying float fade;
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
uniform sampler2D tex4;
void main( void )
{
    vec2 texCoord0 = vec2(gl_TexCoord[0].st * textureScale);
    vec3 texture0 = texture2D( tex0, texCoord0 ).rgb;
    vec3 texture1 = texture2D( tex1, texCoord0 ).rgb;
    vec3 texture2 = texture2D( tex2, texCoord0 ).rgb;
    vec3 texture3 = texture2D( tex3, texCoord0 ).rgb;
    
    vec2 texCoord1 = vec2(gl_TexCoord[0].st);
    // final compose
    vec3 outColor = mix(texture0, texture1, mixture.r);
    outColor = mix(outColor, texture2, mixture.g);
    outColor = mix(outColor, texture3, mixture.b);
    outColor *= ((texture2D( tex4, texCoord1 ).rgb * 0.16)+ 
    			(texture2D( tex4, texCoord1*3 ).rgb * 0.14)+ 
    			(texture2D( tex4, texCoord1*6 ).rgb * 0.12)+ 
    			(texture2D( tex4, texCoord1*9 ).rgb * 0.10)+ 
    			(texture2D( tex4, texCoord1*12 ).rgb * 0.12)+ 
    			(texture2D( tex4, texCoord1*24 ).rgb * 0.14)+ 
    			(texture2D( tex4, texCoord1*32 ).rgb * 0.16))+0.3; 
   
	outColor *= diffuseColor;
    outColor = mix(vec3(0.9,1.0,1.0), outColor, fog);
    gl_FragColor = vec4(outColor, fade);
}